package com.fr.web.core.service;

import com.fr.web.core.SessionIDInfor;
import com.fr.web.core.WebUtils;
import java.io.PrintWriter;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class PDFPrintService extends NoSessionIDService
{
  private static PDFPrintService PDFPRINT_SERVICE = new PDFPrintService();

  public static PDFPrintService getInstance()
  {
    return PDFPRINT_SERVICE;
  }

  public boolean accept(String paramString)
  {
    return ((paramString.equals("pdf_getpdfinstallpath")) || (paramString.equals("fr_pdfprint")) || (paramString.equals("fr_checkpdfprint")));
  }

  public void process(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse, String paramString)
    throws Exception
  {
    if (paramString.equals("fr_pdfprint"))
      dealWithPDFPrint(paramHttpServletRequest, paramHttpServletResponse);
    else if (paramString.equals("pdf_getpdfinstallpath"))
      dealWithPDFInstall(paramHttpServletRequest, paramHttpServletResponse);
    else if (paramString.equals("fr_checkpdfprint"))
      dealWithPDFCheck(paramHttpServletRequest, paramHttpServletResponse);
  }

  public static void dealWithPDFPrint(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    String str4;
    PrintWriter localPrintWriter;
    String str1 = SessionDealWith.getOrGenerateSessionID(paramHttpServletRequest, paramHttpServletResponse);
    if (str1 == null)
      return;
    Map localMap = WebUtils.createTemplateMap(paramHttpServletRequest);
    String str2 = localMap.get("servletURL") + "?op=export&sessionID=" + str1 + "&format=pdf&frandom=" + Math.random() + System.currentTimeMillis() + "&isPDFPrint=true&extype=ori";
    String str3 = WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "codebase");
    if ("true".equals(str3))
    {
      str4 = "<OBJECT ID='PDFReader' WIDTH='100%' HEIGHT='100%' CLASSID='CLSID:CA8A9780-280D-11CF-A24D-444553540000'";
      str4 = str4 + " codebase=\"" + localMap.get("servletURL") + "?op=resource&resource=/AdobeReader.exe\">";
      str4 = str4 + "<param name='src' value='" + str2 + "'></OBJECT>";
      localPrintWriter = WebUtils.createPrintWriter(paramHttpServletResponse);
      localPrintWriter.print(str4);
      localPrintWriter.flush();
      localPrintWriter.close();
    }
    else
    {
      str4 = "<OBJECT ID='PDFReader' WIDTH='0' HEIGHT='0' CLASSID='CLSID:CA8A9780-280D-11CF-A24D-444553540000'><param name='src' value='" + str2 + "'></OBJECT>";
      localPrintWriter = WebUtils.createPrintWriter(paramHttpServletResponse);
      localPrintWriter.print(str4);
      localPrintWriter.flush();
      localPrintWriter.close();
    }
  }

  private void dealWithPDFInstall(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    PrintWriter localPrintWriter = WebUtils.createPrintWriter(paramHttpServletResponse);
    localPrintWriter.write("");
    localPrintWriter.flush();
    localPrintWriter.close();
  }

  private void dealWithPDFCheck(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    PrintWriter localPrintWriter = WebUtils.createPrintWriter(paramHttpServletResponse);
    String str = WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "sessionID");
    SessionIDInfor localSessionIDInfor = SessionDealWith.getSessionIDInfor(str);
    if (localSessionIDInfor == null)
    {
      localPrintWriter.print("error_1");
    }
    else
    {
      Boolean localBoolean = (Boolean)localSessionIDInfor.getAttribute("genpdfprint");
      if ((localBoolean != null) && (localBoolean.booleanValue()))
        localPrintWriter.print("gening");
      else
        localPrintWriter.print("ok");
    }
    localPrintWriter.flush();
    localPrintWriter.close();
  }
}